package com.jtzc.aikf.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jtzc.aikf.entity.Appointment;
import com.jtzc.aikf.entity.DocumentDO;
import com.jtzc.aikf.service.DocumentService;
import com.jtzc.aikf.service.KnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.UUID;

/**
 * @author wu chuang
 * @description
 */
@RestController
public class KnowledgeController {

    @Autowired
    private KnowledgeService knowledgeService;

    @Autowired
    private DocumentService documentService;
    @GetMapping("knowlegeList")
    public Page<DocumentDO> list(){
        Page<DocumentDO> objectPage = new Page<>();
        objectPage.setCurrent(1);
        objectPage.setSize(10);
        Page<DocumentDO> page = knowledgeService.page(objectPage);
        return page;
    }
    @PostMapping("/upload")
    public String handleFileUpload(
            @RequestParam("file") MultipartFile file) {
        try {
            knowledgeService.upload(file);
            return "文件上传成功";
        } catch (Exception e) {
            return "文件上传失败";
        }
    }

    @GetMapping("/relearn")
    public String relearn(@RequestParam("docId") Integer docId) {
        try {
            knowledgeService.relearn(docId);
            return "文件上传成功";
        } catch (Exception e) {
            return "文件上传失败";
        }
    }

}
